package com.mmy.dao.bidtender;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.bidtender.TBidTender;

public interface TBidTenderRepository extends JpaRepository<TBidTender, Integer> {
	/**
	 * 获得最大编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.10
	 */
	@Query(value = "select MAX(iTenderID)  from tBidTender  where LEFT(iTenderID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxTenderID();

	/* 创建投标信息 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tBidTender(iTenderID, iInviteID, iOrgID, fBudget, dOutDate, dBackDate, cOwn, cTips, cStandard, iDay, cExplain,iState, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, 0, 0, 0.00, '2020-01-01 00:00:00', '2020-01-01 00:00:00', NULL, NULL, NULL, 0, NULL,0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int tenderID);
	/* 创建修改投标 自带 */

	@Query(value = "select *  from tBidTender where  iTenderID=?1", nativeQuery = true)
	TBidTender findByiTenderID(int iTenderID);

	@Transactional
	@Modifying
	@Query(value = "delete from tBidTender where iTenderID in (:iTenderIDs)", nativeQuery = true)
	void deleteChecked(@Param("iTenderIDs") List<Integer> iTenderIDs);

	/**
	 * 查询投标ID
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.11.19
	 */
	@Query(value = "select *  from tBidTender where  iTenderID=?1", nativeQuery = true)
	TBidTender findByTenderID(int iTenderID);

	/**
	 * 通过招标ID查询状态为未中标的投标信息 中标时用到 查询后修改投标状态为终止
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select * from tBidTender where iInviteID=?1 and iState=1", nativeQuery = true)
	List<TBidTender> findByInviteID(int iInviteID);
}
